import sys
import os.path
import threading

import cherrypy
from mako.template import Template
from mako.lookup import TemplateLookup

settings = {
    '/': {
        'tools.staticdir.root': sys.path[0]
    },
    '/css/theme.css': {
        'tools.staticfile.on': True,
        'tools.staticfile.filename': os.path.join(sys.path[0], "themes/default/theme.css")
    },
    '/js': {
        'tools.staticdir.on': True,
        'tools.staticdir.dir': "js"
    }
}

templates = TemplateLookup(directories=['templates'])

class WebServer(threading.Thread):

    def __init__(self):
        threading.Thread.__init__(self)
        
    def run(self):
        cherrypy.quickstart(MainPage(), '/', settings)
        
    def stop(self):
        cherrypy.engine.stop()
        cherrypy.engine.exit()

class MainPage(object):

    @cherrypy.expose
    def index(self):
        template = templates.get_template("scoreboard.html")
        return template.render()        
